package org.raymond.iworks.study.basic.thread;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
public class DeadLock {
    private static Object lock1 = new Object();
    private static Object lock2 = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            synchronized (lock1){
                System.out.println("Thread-1 获取了锁1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lock2){
                    System.out.println("Thread-1 尝试获取锁2");
                }
            }
        });

        Thread t2 = new Thread(()->{
            synchronized (lock2){
                System.out.println("Thread-2 获取了锁2");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lock1){
                    System.out.println("Thread-2 尝试获取锁1");
                }
            }
        });

        t1.start();
        t2.start();
        // 测试镜像
    }
}
